package com.itlong.cloud.controller.sharedelevator;

import com.itlong.cloud.POJO.DTO.property.ConsumptionRecordDTO;
import com.itlong.cloud.POJO.VO.MessageVO;
import com.itlong.cloud.POJO.VO.property.ConsumptionRecordVO;
import com.itlong.cloud.enumerate.ecode.BaseErrorCodeEnum;
import com.itlong.cloud.equip.property.IPropertyConsumptionServiceClient;
import com.itlong.cloud.thrown.DataAccessException;
import com.itlong.cloud.utils.network.http.HttpProtocolUtil;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <desc>
 *      运营消费管理控制器
 * </desc>
 *
 * @createDate2020/7/16
 **/
@RestController
@RequestMapping("/sharedElevator/consumption")
public class OperateConsumptionController {

    @Autowired
    private IPropertyConsumptionServiceClient iPropertyConsumptionServiceClient;

    /**
     * <desc>
     *      分页获取消费管理列表
     * </desc>
     *
     * @param consumptionRecordDTO 消费记录DTO
     * @return 消费记录分页列表
     * @Author Zhu.yj
     * @createDate  2020/7/16
     */
    @RequestMapping(value = "getPage", method = RequestMethod.POST)
    public Object getPage(ConsumptionRecordDTO consumptionRecordDTO, HttpServletRequest request){
        try{
            consumptionRecordDTO = HttpProtocolUtil.parseRequestParamToDTO(ConsumptionRecordDTO.class, request);
            if (consumptionRecordDTO == null){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            Page<ConsumptionRecordVO> page = iPropertyConsumptionServiceClient.getPage(consumptionRecordDTO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), page);
        }catch (Exception e){
            throw new DataAccessException("【运营_消费管理_分页获取消费记录】分页获取消费记录失败", e);
        }
    }
}
